package com.sky.controller.admin;

/**
 * @Author 褚金龙
 * @Date 2024/8/31 18:25
 */

import com.sky.annotation.AutoFill;
import com.sky.dto.category.CategoryPageDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.category.CategoryService;
import com.sky.vo.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分类表
 */

@Slf4j
@RestController
@RequestMapping("/admin/category")
@CrossOrigin("*")
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 分类表分页查询
     * @param categoryPageDTO
     * @return
     */
    @ApiOperation("分页查询信息")
    @GetMapping
    public Result page(CategoryPageDTO categoryPageDTO){

        PageResult pageResult = categoryService.pageService(categoryPageDTO);
        return  Result.success(pageResult);
    }

    /**
     * 根据id查询分类信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询分类信息")
    public Result queryCategory(@PathVariable Integer id ){
       CategoryVO categoryVO= categoryService.queryCategoryService(id);
        return  Result.success(categoryVO);
    }


    /**
     * 修改分类
     * @param categoryVO
     * @return
     */
    @PutMapping()
    @ApiOperation("修改分类")

   public Result updateCategory(@RequestBody CategoryVO categoryVO){

        categoryService.updateCategory(categoryVO);
        return Result.success();
   }

    /**
     * 修改分类状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工状态")

   public Result statusUpdate(@PathVariable Integer status, @RequestBody Integer id){


        categoryService.statusUpdate(status,id);
       return  Result.success();
   }

    /**
     * 删除分类
     * @param id
     * @return
     */
   @DeleteMapping("/{id}")
   @ApiOperation("删除分类")
   public Result deleteCategory(@PathVariable Integer id){
       categoryService.deleteCategoryService(id);
       return Result.success();
   }

   @PostMapping("/addCategory")
   @ApiOperation("添加分类")
   public Result addCategory(@RequestBody Category category){

       categoryService.insertCategoryService(category);
       return Result.success();
   }

}
